// import store from 'store'
import * as types from '@/store/mutation-types'
import api from '@/tools/api.js'
// import { SUCCESS_STATUS } from '@/config/status'
import promise from '@/tools/promise'

const state = {
  list: [],
  pageData: {
    total: 1,
    per_page: 15,
    current_page: 1,
    last_page: 1
  }
}

// mutations
const mutations = {
  // 后台获取实名认证分页列表数据
  [types.GET_AUTHENTICATION_LIST] (state, payload) {
    state.list = payload.data
    state.pageData.total = Number(payload.total)
    state.pageData.per_page = Number(payload.per_page)
    state.pageData.current_page = Number(payload.current_page)
    state.pageData.last_page = Number(payload.last_page)
  }
}

// actions
const actions = {
  // 后台获取实名认证分页列表数据
  async getList ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在获取实名认证分页数据'}
    let getListRes = await api('serveruser/user/User/getAuthticationList', payload, config)
    // 这里注释原因：当获取数据为空时，仍显示上一次获取到的内容
    // SUCCESS_STATUS === getListRes.status && commit(types.GET_AUTHENTICATION_LIST, getListRes.res)
    commit(types.GET_AUTHENTICATION_LIST, getListRes.res)
  },
  // 后台进行审核实名认证
  async auditPass ({ commit }, payload) {
    let config = {loading: true, loadingText: '正在审核中...'}
    let auditRes = await api('serveruser/user/User/verifyAuthentication', payload, config)
    return promise(auditRes)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
